<template>
	<view class="container">
		<view class="address-card" @click="selectAddress">
			<view v-if="address.id" class="address-info">
				<view class="info-top f-a-baseline">
					<view class="name">{{address.realname}}</view>
					<view class="phone">{{address.mobile}}</view>
				</view>
				<view class="info-bottom f-a-start">
					<image src="/static/order/icon-address.png" class="icon-address"></image>
					<view class="detail">{{address.province}}{{address.city}}{{address.distinct}}{{address.address}}</view>
				</view>
			</view>
			<view v-else class="address-empty">暂无地址，请前往添加地址</view>
			<view class="icon-right">
				<u-icon bold name="arrow-right" color="#676767" size="28rpx"></u-icon>
			</view>
			<image src="/static/order/envelope-line.png" class="envelope-line"></image>
		</view>

		<view class="goods-content">
			<view class="goods-list">
				<view class="comp-item" v-for="(item,i) in submitList" :key="item.id">
					<submitProduct :item="item" :notAddCart="false" @onNumChange="num=>onNumChange(item,num)">
					</submitProduct>
				</view>
			</view>

			<view class="base-info">
				<view class="fee f-c-between">
					<view>运费</view>
					<view class="value f-a-center">
						<span style="margin-right: 10rpx;">免邮</span>
						<u-icon bold name="arrow-right" color="#676767" size="22rpx" top="0px"></u-icon>
					</view>
				</view>
				<view class="fee f-a-center" style="margin-top: 20rpx;">
					<view>订单备注</view>
					<view class="remark">
						<u--input v-model.trim="remark" placeholder="建议备注前先与客服沟通确认" maxLength="50" border="none" fontSize="28rpx"
							placeholderStyle="color:#676767" style="width: 100%;"></u--input>
					</view>
				</view>
			</view>
		</view>

		<view class="footer-fixed f-c-between">
			<view class="fixed-left f-a-center">
				<view class="price">{{submitAllGoodsPrice}}</view>
				<view class="num">共{{submitAllGoodsCount}}件</view>
			</view>
			<button class="btn-submit" @click="submitOrder">提交订单</button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex'
	export default {
		data() {
			return {
				address: {},
				remark: '',
				submitList: [],
				submitTotal: {
					totalPrice: 0,
					totalNum: 0
				}
			}
		},
		computed: {
			...mapGetters(['submitSubmitType', 'submitGoodsNumList', 'submitAllGoodsCount', 'submitAllGoodsPrice']),
		},
		onLoad() {
			this.submitList = this.submitGoodsNumList
		},
		onShow() {
			this.getDefaultAddress()
			uni.$on('addressInfo', (data) => {
				this.address = data
			})
		},
		methods: {
			//获取默认地址
			getDefaultAddress() {
				this.$api.get_address_default().then(res => {
					this.address = res || {}
				})
			},

			//选择地址
			selectAddress() {
				uni.navigateTo({
					url: '/pages/address/list'
				})
			},

			// 数量改变
			onNumChange(item, num) {
				this.$store.dispatch('ac_submit_goodsChange', {
					item,
					num
				})
			},

			// 提交订单
			submitOrder() {
				if (!this.address?.id) {
					uni.showToast({
						icon: 'none',
						title: '请选择地址'
					})
					return
				}
				let params = {
					addressId: this.address?.id,
					mark: this.remark,
					price: this.submitAllGoodsPrice
				}
				uni.navigateTo({
					url: '/pages/cart/pay?' + this.$util.businessUtil.paramURL(params)
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #F4F7F7;
	}
</style>
<style lang="scss" scoped>
	.address-card {
		background-color: #ffffff;
		position: relative;

		.icon-right {
			position: absolute;
			right: 36rpx;
			top: 50%;
			transform: translateY(-50%);
		}

		.address-empty {
			padding: 72rpx 106rpx;
			text-align: center;
			font-weight: 400;
			// font-size: 24rpx;
			font-size: calc(24rpx * 1.5);
			color: #333333;
		}

		.address-info {
			padding: 28rpx 106rpx 24rpx 44rpx;

			.info-top {
				padding-left: 4rpx;

				.name {
					font-weight: 500;
					font-size: 32rpx;
					color: #333333;
				}

				.phone {
					font-weight: 400;
					// font-size: 24rpx;
					font-size: calc(24rpx * 1.2);
					color: #676767;
					margin-left: 14rpx;
				}
			}

			.info-bottom {
				margin-top: 10rpx;

				.icon-address {
					min-width: 28rpx;
					max-width: 28rpx;
					height: 28rpx;
					margin-right: 8rpx;
				}

				.detail {
					font-weight: 400;
					// font-size: 24rpx;
					font-size: calc(24rpx * 1.2);
					color: #333333;
					line-height: 32rpx;
				}
			}
		}

		.envelope-line {
			width: 100%;
			height: 4rpx;
			display: block;
		}
	}

	.goods-content {
		margin: 20rpx 24rpx 200rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 18rpx 0px rgba(0, 0, 0, 0.11);
		border-radius: 16rpx;

		.goods-list {
			padding: 30rpx 24rpx 0 32rpx;
			border-bottom: 1px solid #cfccc6;

			.comp-item {
				padding-bottom: 30rpx;
			}
		}

		.base-info {
			padding: 30rpx 24rpx 30rpx 20rpx;

			.fee {
				font-weight: 400;
				// font-size: 25rpx;
				font-size: calc(26rpx * 1.2);
				color: #333333;

				.value {
					font-weight: 400;
					// font-size: 24rpx;
					font-size: calc(24rpx * 1.2);
					color: #EC673F;
				}

				.remark {
					flex: 1;
					margin-left: 38rpx;
				}
			}
		}
	}

	.footer-fixed {
		padding: 18rpx 24rpx 18rpx 70rpx;
		background-color: #FFFFFF;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;

		.fixed-left {
			.price {
				font-weight: 400;
				font-size: 56rpx;
				color: #FF5800;
				position: relative;

				&:before {
					content: '¥';
					font-size: 32rpx;
					margin-right: 4rpx;
				}
			}

			.num {
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
				margin-left: 40rpx;
				padding-top: 8rpx;
			}
		}

		.btn-submit {
			width: 224rpx;
			height: 70rpx;
			line-height: 70rpx;
			background: #FFC046;
			border-radius: 35rpx;
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
		}
	}
</style>